/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fhm;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 *
 * @author Student
 */
public class FHM {

    static String word = "";

    public static void printCurrent(char currentArray[]) {
        for (int i = 0; i < currentArray.length; i++) {
            System.out.print(currentArray[i]);
        }
    }

    public static void main(String[] args) {        //Intro.
        System.out.println("Welcome."); //welcolm
        int tries = 0;
        //Grab word for other user to guess.
        Scanner keyboard = new Scanner(System.in); //creates scanner
        System.out.print("PLAYER ONE!!! PUT IN A WORD:  ");//prompts user for word
        word = keyboard.nextLine(); //user puts in guessing word
        //When we have the word, add it all to an array.
        char finalArray[] = word.toCharArray();    //arr is now an array of the words.
        char currentArray[] = new char[word.length()]; //creats current array
        ArrayList<Character> guessed = new ArrayList(); //creates guessed array list
        ArrayList<String> pic = new ArrayList(); //creatse array list called pic
        pic.add("----------\n	||\n	||\n	||");//0
        pic.add("----------\n	||\n	||\n	||\n	O");//1
        pic.add("----------\n	||\n	||\n	||\n	O\n	 |");
        pic.add("----------\n	||n	||\n	||\n    O\n	/|  \n");    //makes hang man in pic array
        pic.add("----------\n	||\n	||\n	||\n	O\n	/|\\\n");
        pic.add("----------\n	||\n	||\n	||\n	O\n	/|\\\n        /\n");
        pic.add("----------\n	||\n	||\n	||\n	O\n	/|\\\n        /\\\n");



        for (int i = 0; i < word.length(); i++) {
            if (word.charAt(i) == ' ') {
                currentArray[i] = ' ';       //sets what user puts in current array and puts "_" if i is a space
            } else {
                currentArray[i] = '_';
            }
        }

        //Game starts here!!!!!!!!!!!!
        while (true) {
            for (int i = 0; i < 10; i++)//creats for loop of spaces to ten to seem like picture is constant
            {
                System.out.println("");
            }
            //Here we want to print out the picture.
            System.out.println(pic.get(tries));
            if (tries == 7) {
                System.out.println("GAME OVER"); //shows that after tries = 7. the gsme is over and will end
               //Prompt to play again.
            }

            //Prints out all the guessed letters
            for (int i = 0; i < guessed.size(); i++) {
                System.out.println(guessed.get(i));
            }
            //Prints out the players current phrase and what they got right.
            for (int i = 0; i < currentArray.length; i++) {
                System.out.print(currentArray[i]);

            }
            System.out.println("");

            System.out.print("Player 2, Add your letter: ");
            char tempLetter = keyboard.nextLine().charAt(0); //prompting player two to guess letter

            int numCheck = 0; //adding interger numcheck which is used to show amount of letters taht are wrong for word
            for (int i = 0; i < finalArray.length; i++) {
                if (finalArray[i] == tempLetter) {
                    //Add temp letter to that position in current array
                    currentArray[i] = tempLetter;
                } //else increase the number
                else {
                    numCheck++; //increases numcheck by one each time a letter is wrong
                }

            }

            if (numCheck == finalArray.length) {
                System.out.println("WRONG guess AGAIN!!!");  //actually shows that when numCheck == final array's length, wrong is showed
                guessed.add(tempLetter);
                tries++;


            }
            //Check to see if all the areas aren't _'s to see if they win.

            int runner = 0;
            for (int i = 0; i < currentArray.length; i++) {
                if (currentArray[i] != '_') {
                    runner++;
                    //System.out.println("YOU WIN!!!! play again!?!");
                }
            }
            if(runner == currentArray.length)
            {
                System.out.println("YOU WIN!!!! play again!?!");
                //Prompt to play agai.
            }
        }

    }
}